﻿using System.Runtime.InteropServices;

namespace SceneUnpacker.Schematrix
{
    public sealed class DriveInfo
    {
        private readonly long _free;
        private long Allocated;
        public readonly long Available;
        public readonly string Drive;
        public readonly long Result;
        public readonly long Total;

        public DriveInfo(string drive)
        {
            long num2;
            long num3;
            long num4;
            long num = GetDiskFreeSpaceEx(drive, out num2, out num3, out num4);
            this.Drive = drive;
            this.Result = num;
            this.Available = num2;
            this.Total = num3;
            this._free = num4;
        }

        internal void Allocate(int p2)
        {
            this.Allocated += p2;
        }

        internal bool CanAllocte(int p2)
        {
            return ((this.Free - p2) > 0L);
        }

        [DllImport("kernel32.dll", EntryPoint="GetDiskFreeSpaceExA")]
        private static extern long GetDiskFreeSpaceEx(string lpDirectoryName, out long lpFreeBytesAvailableToCaller, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);

        public long Free
        {
            get
            {
                return (this._free - this.Allocated);
            }
        }
    }
}

